import fire from '@dfeidao/atom-web/msg/fire';

import render from '@dfeidao/atom-web/render/render';
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';

import P03 from './P03';

import get from '@dfeidao/atom-web/local/get';
import remove from '@dfeidao/atom-web/local/remove';
import set from '@dfeidao/atom-web/local/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';
import hide_loading from '../../atom/hide-loading';
import show_loading from '../../atom/show-loading';

interface Aa {
	role_no: string;
	role_type_id: string;
	group_id: string;
}
export default async function a022(fd: IFeidaoAiBrowserComponent, group_id: string, role_allot_id: string, id: string) {
	//  调用事件
	const productid = get(fd, 'productid');
	const _id = get(fd, 'role_allot_id') as string;
	remove(fd, 'shezhi');
	show_loading();
	const res = await nodejs<{ dataArray: object[], count: number }>('roler/zj-000004/s019', { productid, role_allot_id, group_id });
	hide_loading();
	if (res.count === 0) {
		render(fd, '', P03, 'P03', 'inner');
	} else {
		const data = res.dataArray.map((v) => {
			return { ...v, v: JSON.stringify(v) };
		});
		render(fd, data, P03, 'P03', 'inner');
		if (id) {
			const items = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-id5="' + id + '"]');
			set_node_cls(items, 'bg-c', true);
			const v = items.getAttribute('v');
			const obj = JSON.parse(v);
			const role = get(fd, 'role') as Aa;
			const role_type_id = role.role_type_id;
			const allot_group = get(fd, 'allot_group') as Aa;
			obj.parent_group_id = allot_group.group_id;
			obj.role_type_id = role_type_id;
			obj.role_allot_id = _id;
			set(fd, 'shezhi', obj);
		}
	}
	const query = {
		productid, role_allot_id: _id, group_id
	};
	fire('zj-000004', 'eu-013', query);
}
